package edu.yuhf.web.controller;

import edu.yuhf.domain.User;
import edu.yuhf.service.iface.UserService;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("api/v1/user")
@Log4j2
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("/login")
    public ModelAndView userLogin(@RequestParam String userName,@RequestParam String password){
        ModelAndView mav=new ModelAndView();
        if(userService.checkUserNameAndPassword(userName,password)){
            mav.setViewName("views/main");
        }else{
            mav.addObject("message","用户名或密码错误！");
            mav.setViewName("login");
        }
        return mav;
    }

}
